<template>
  <view class="container">
    <view class="header">
      <view class="header-decoration">
      </view>
      <text class="title">育儿补贴计算器</text>
      <text class="subtitle">根据《育儿补贴制度实施方案》，快速计算您家庭可领取的育儿补贴金额</text>
    </view>
    
    <view class="content">
      <view class="calculator-card">
        <view class="card-title">
          <text>补贴计算器</text>
          <button class="share-btn" open-type="share">分享给好友</button>
        </view>
        
        <view class="input-group">
          <text class="label">
            孩子出生日期
          </text>
          <picker mode="date" :value="childBirthdate" @change="bindDateChange"  start="2022-01-01" end="2030-12-31">
            <view class="picker">
              {{ formatDate(childBirthdate) }}
            </view>
          </picker>
        </view>
        
        <view class="input-group">
          <text class="label">
            孩子数量
          </text>
          <view class="number-input">
            <text class="number-btn" @click="decreaseChildCount">-</text>
            <input type="number" v-model="childCount" disabled />
            <text class="number-btn" @click="increaseChildCount">+</text>
          </view>
        </view>
        
        <button class="btn-calculate" @click="() => calculateSubsidy()">
          计算补贴金额
        </button>
        
        <view class="result-container" v-if="showResult">
          <view class="result-title">您的育儿补贴总额为</view>
          <view class="result-amount">¥{{ formattedAmount }}</view>
          <view class="result-detail">
            <text>根据您的输入：\n</text>
            <text>- 孩子出生于：{{ formatDate(childBirthdate) }}\n</text>
            <text>- 孩子数量：{{ childCount }}名\n</text>
            <text>- {{ detailText }}</text>
          </view>
        </view>
      </view>
      
      <view class="policy-card">
        <view class="card-title">
          <text>政策要点</text>
        </view>
        
        <view class="policy-points">
          <view class="policy-item" v-for="(item, index) in policyPoints" :key="index">
            <text class="policy-item-title">{{ item.title }}</text>
            <text class="policy-item-content">{{ item.content }}</text>
          </view>
        </view>
      </view>
    </view>
    
    <view class="info-container">
      <view class="info-title">
        <text>补贴计算说明</text>
      </view>
      <text class="info-text">育儿补贴制度是国家为支持家庭养育婴幼儿，缓解家庭养育压力，按照一定标准发放补贴的制度。</text>
      
      <text class="info-subtitle">计算规则：</text>
      <view class="info-list">
        <view class="info-list-item">2025年1月1日及以后出生的婴幼儿：可连续申领3年补贴，共计10800元</view>
        <view class="info-list-item">2025年1月1日前出生且未满3周岁的婴幼儿：按应补贴月数折算补贴金额（每月300元）</view>
        <view class="info-list-item">补贴金额 = 补贴月数 × 300元 × 孩子数量</view>
      </view>
      
      <text class="info-subtitle">申领所需信息：</text>
      <view class="info-list">
        <view class="info-list-item">婴幼儿姓名、证件号码、出生日期、性别、户籍地址</view>
        <view class="info-list-item">申领人姓名、证件号码、手机号、现居住地址</view>
        <view class="info-list-item">收款账户信息</view>
      </view>
    </view>
    
    <view class="disclaimer">
      本计算器根据《育儿补贴制度实施方案》制作，仅供参考。实际金额以当地政府最终政策为准。
    </view>
  </view>
  <FloatButton />
</template>

<script>
import { getShareAppMessageConfig, getShareTimelineConfig } from '../../utils/share.js';
import FloatButton from '@/components/FloatButton.vue'

export default {
  components: {
    FloatButton
  },
  components: {
    
  },
  data() {
    return {
      childBirthdate: '2025-01-01',
      childCount: 1,
      showResult: false,
      formattedAmount: '0',
      detailText: '',
      policyPoints: [
        {
          title: '补贴对象',
          content: '从2025年1月1日起，符合法律法规规定生育的3周岁以下婴幼儿（具有中国国籍），无论一孩、二孩、三孩均可申领。'
        },
        {
          title: '补贴标准',
          content: '国家基础标准为每孩每年3600元，按月折算为每月300元，至其年满3周岁。'
        },
        {
          title: '申领方式',
          content: '以线上申请为主，可通过支付宝、微信平台"育儿补贴"小程序或婴幼儿户籍所在省份的政务服务平台申请。'
        },
        {
          title: '申领时间',
          content: '各地预计2025年8月下旬陆续开放申领育儿补贴，请关注当地政府公告。'
        },
        {
          title: '其他优惠',
          content: '育儿补贴免征个人所得税，在最低生活保障对象等救助对象认定时不计入家庭或个人收入。'
        }
      ]
    }
  },
  onLoad() {
  },
  // 分享到聊天
  onShareAppMessage() {
    return getShareAppMessageConfig({
      title: '育儿补贴计算器 - 快速计算您家庭可领取的补贴金额',
      path: '/pages-sub/calculator/childAllowance',
      imageUrl: '/static/share-allowance.png'
    });
  },
  // 分享到朋友圈
  onShareTimeline() {
    return getShareTimelineConfig({
      title: '育儿补贴计算器 - 快速计算您家庭可领取的补贴金额',
      imageUrl: '/static/share-allowance.png'
    });
  },
  
  // 分享给朋友
  onShareAppMessage() {
    return {
      title: '育儿补贴计算器 - 快速计算您家庭可领取的补贴金额',
      path: '/pages-sub/calculator/childAllowance',
      imageUrl: '/static/share-allowance.png',
      success: function() {
        uni.showToast({
          title: '分享成功',
          icon: 'success'
        });
      }
    };
  },
  methods: {
    
    bindDateChange(e) {
        console.log('选择的日期：', e.detail.value);
      this.childBirthdate = e.detail.value;
    //   this.calculateSubsidy();
    },
    increaseChildCount() {
      if (this.childCount < 5) {
        this.childCount++;
        // this.calculateSubsidy();
      }
    },
    decreaseChildCount() {
      if (this.childCount > 1) {
        this.childCount--;
        // this.calculateSubsidy();
      }
    },
    formatDate(dateString) {
      const date = new Date(dateString);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, '0');
      const day = date.getDate().toString().padStart(2, '0');
      return `${year}年${month}月${day}日`;
    },
    calculateSubsidy() {
      // 解析日期
      const birthdate = new Date(this.childBirthdate);
      const policyStart = new Date('2025-01-01');
      
      // 计算补贴月数
      let months = 0;
      
      if (birthdate >= policyStart) {
        // 2025年1月1日或之后出生
        months = 36; // 3年 × 12个月
        this.detailText = `2025年1月1日及之后出生，可领取完整36个月育儿补贴`;
      } else {
        // 2025年1月1日前出生
        const childThirdBirthday = new Date(birthdate);
        childThirdBirthday.setFullYear(birthdate.getFullYear() + 3);
        
        // 计算从2025年1月到满三周岁当月的月数
        const startYear = 2025;
        const startMonth = 0; // 0代表1月
        
        const endYear = childThirdBirthday.getFullYear();
        const endMonth = childThirdBirthday.getMonth(); // 0-11代表月份
        
        months = (endYear - startYear) * 12 + (endMonth - startMonth) + 1;
        months = Math.max(0, months); // 确保月数不为负数
        
        this.detailText = `2025年1月1日前出生，可领取${months}个月育儿补贴`;
      }
      
      // 计算总金额
      const amountPerChild = months * 300;
      const totalAmount = amountPerChild * this.childCount;
      
      // 格式化金额显示
      this.formattedAmount = totalAmount.toLocaleString();
      
      this.showResult = true;
    }
  }
}
</script>

<style>
.container {
  padding: 30rpx;
  background: linear-gradient(135deg, #e0f7fa 0%, #f8bbd0 100%);
  color: #333;
  min-height: 100vh;
}

.header {
  text-align: center;
  margin-bottom: 30rpx;
  padding: 40rpx;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 30rpx;
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.header-decoration {
  position: absolute;
  top: -20rpx;
  right: -20rpx;
  font-size: 120rpx;
  color: rgba(233, 30, 99, 0.1);
  transform: rotate(20deg);
  z-index: 1;
}

.title {
  font-size: 56rpx;
  color: #e91e63;
  margin-bottom: 30rpx;
  position: relative;
  z-index: 2;
  font-weight: bold;
  display: block;
}

.subtitle {
  font-size: 28rpx;
  color: #555;
  position: relative;
  z-index: 2;
  display: block;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.calculator-card, .policy-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 30rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
  padding: 40rpx;
}

.card-title {
  color: #e91e63;
  margin-bottom: 40rpx;
  padding-bottom: 20rpx;
  border-bottom: 4rpx solid #f8bbd0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 36rpx;
  font-weight: bold;
}

.share-btn {
  background-color: #e91e63;
  color: white;
  font-size: 24rpx;
  padding: 0 20rpx;
  height: 60rpx;
  line-height: 60rpx;
  border-radius: 30rpx;
  margin: 0;
  box-shadow: 0 4rpx 10rpx rgba(233, 30, 99, 0.3);
}

.input-group {
  margin-bottom: 40rpx;
}

.label {
  display: block;
  margin-bottom: 16rpx;
  font-weight: 600;
  color: #555;
  font-size: 32rpx;
}

.picker {
  padding: 28rpx;
  border: 4rpx solid #f48fb1;
  border-radius: 20rpx;
  font-size: 32rpx;
  background-color: #fff;
}

.number-input {
  display: flex;
  align-items: center;
  border: 4rpx solid #f48fb1;
  border-radius: 20rpx;
  overflow: hidden;
  background-color: #fff;
}

.number-btn {
  width: 80rpx;
  height: 80rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40rpx;
  font-weight: bold;
  color: #e91e63;
  background-color: #fce4ec;
}

.number-input input {
  flex: 1;
  height: 80rpx;
  text-align: center;
  font-size: 32rpx;
  border: none;
}

.baby-icon {
  color: #e91e63;
  font-size: 32rpx;
  margin-right: 10rpx;
}

.btn-calculate {
  background: linear-gradient(135deg, #e91e63 0%, #f48fb1 100%);
  color: white;
  border: none;
  padding: 30rpx;
  font-size: 36rpx;
  border-radius: 20rpx;
  margin-top: 20rpx;
  font-weight: 600;
  box-shadow: 0 8rpx 15rpx rgba(233, 30, 99, 0.3);
}

.result-container {
  margin-top: 40rpx;
  text-align: center;
  padding: 30rpx;
  background: #f8f9fa;
  border-radius: 20rpx;
  border-left: 10rpx solid #e91e63;
}

.result-title {
  font-size: 32rpx;
  color: #555;
  margin-bottom: 20rpx;
}

.result-amount {
  font-size: 70rpx;
  font-weight: 700;
  color: #e91e63;
  margin: 20rpx 0;
}

.result-detail {
  font-size: 28rpx;
  color: #666;
  line-height: 1.8;
  text-align: left;
}

.policy-points {
  display: flex;
  flex-direction: column;
  gap: 30rpx;
}

.policy-item {
  padding: 30rpx;
  background: #f9f9f9;
  border-radius: 20rpx;
  border-left: 8rpx solid #e91e63;
}

.policy-item-title {
  color: #e91e63;
  margin-bottom: 20rpx;
  font-size: 32rpx;
  font-weight: bold;
  display: block;
}

.policy-item-content {
  color: #555;
  line-height: 1.7;
  font-size: 28rpx;
}

.info-container {
  margin-top: 40rpx;
  background: rgba(255, 255, 255, 0.9);
  padding: 40rpx;
  border-radius: 30rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.05);
}

.info-title {
  color: #e91e63;
  margin-bottom: 30rpx;
  font-size: 36rpx;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 10rpx;
}

.info-text {
  color: #555;
  margin-bottom: 30rpx;
  line-height: 1.7;
  font-size: 28rpx;
  display: block;
}

.info-subtitle {
  color: #333;
  font-weight: bold;
  margin: 20rpx 0;
  font-size: 32rpx;
  display: block;
}

.info-list {
  padding-left: 20rpx;
  margin-bottom: 30rpx;
}

.info-list-item {
  margin-bottom: 20rpx;
  position: relative;
  padding-left: 30rpx;
  font-size: 28rpx;
  color: #555;
  line-height: 1.6;
}

.info-list-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 16rpx;
  width: 12rpx;
  height: 12rpx;
  background-color: #e91e63;
  border-radius: 50%;
}

.disclaimer {
  margin-top: 40rpx;
  text-align: center;
  padding: 30rpx;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 20rpx;
  font-size: 24rpx;
  color: #777;
}

/* 适配小屏幕设备 */
@media screen and (max-width: 768rpx) {
  .title {
    font-size: 44rpx;
  }
  
  .result-amount {
    font-size: 56rpx;
  }
}
</style>